<template>
    <div>
        <breadcrumb :title="'通知管理'" :noBack="true"></breadcrumb>
        <div class="white-block box" v-loading="loading">
            <div class="text-right">
                <el-button type="primary" size="small" @click="$router.push($route.path+'/add')">新增通知</el-button>
            </div>
            <table-example :data="tableData" :tableColumn="header" :slotColumns="slotColumns" class="mt20">
                <!--接受scope-->
                <template slot="operation" slot-scope="scope">
                    <el-link type="primary" :underline="false" class="mr10"
                             @click="$router.push($route.path+'/'+scope.row.noticeId)">
                        编辑
                    </el-link>
                    <el-link type="primary" :underline="false" @click="removeList(scope.row.noticeId)">删除</el-link>
                </template>
                <template slot="date" slot-scope="scope">
                    {{scope.row.noticeStartTime +' - '+ scope.row.noticeEndTime}}
                </template>
                <template slot="noticeStatus" slot-scope="scope">
                    <span v-if="scope.row.noticeStatus==0" class="error">未开始</span>
                    <span v-else-if="scope.row.noticeStatus==1">公告中</span>
                    <span v-else class="closure">已结束</span>
                </template>
            </table-example>
            <page :data="data" v-if="data" class="mt20 page" @jumpPage="getList"></page>
        </div>
        <transition name="slide">
            <router-view @upload="getList"></router-view>
        </transition>
    </div>
</template>

<script>
    import breadcrumb from '../../components/breadcrumb'
    import tableExample from '../../components/table'
    import page from '../../components/pagination'

    export default {

        data() {
            return {
                tableData: [],
                header: [
                    {
                        prop: 'noticeName',
                        label: '通知名称',
                        minWidth: '17%',
                        align: 'center'
                    },
                    {
                        prop: 'date',
                        label: '通知时间',
                        minWidth: '34%',
                        align: 'center'
                    },
                    {
                        prop: 'noticePlatformName',
                        label: '发布平台',
                        minWidth: '17%',
                        align: 'center'
                    },
                    {
                        prop: 'lastUpdateTime',
                        label: '最后更新时间',
                        minWidth: '17%',
                        align: 'center'
                    },
                    {
                        prop: 'noticeStatus',
                        label: '当前状态',
                        minWidth: '15%',
                        align: 'center'
                    },
                    {
                        prop: 'operation',
                        label: '操作',
                        minWidth: '17%',
                        align: 'center'
                    }
                ],
                slotColumns: ['operation', 'noticeStatus', 'date'],
                data: null,
                input: '',
                value: '',
                loading: false,
                index: 1
            }
        },
        mounted() {
            this.getList()
        },
        methods: {
            getList(index) {
                this.loading = true
                if (index) this.index = index
                this.$http.get('/gsNotice/getList', {
                    current: this.index || 1,
                    size: 10
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.tableData = result.data.records
                        this.data = result.data
                        delete this.data['records']
                    }
                    this.$method.updateView()
                }).catch(() => {
                    this.loading = false
                })
            },
            removeList(id) {
                this.loading = true
                this.$http.post('/gsNotice/deleteById', {
                    noticeId: id
                }).then(result => {
                    if (result.success) {
                        this.getList()
                    } else {
                        this.loading = false
                    }
                }).catch(() => {
                    this.loading = false
                })
            }
        },
        components: {
            tableExample,
            breadcrumb,
            page
        }
    }
</script>

<style scoped lang="less">
    .box {
        .input {
            width: 2.8rem;
            height: 0.5rem;
            line-height: 0.5rem;
        }

        .btn {
            border-radius: 0;
        }

        .btn-s {
            padding: 0 0.08rem;
        }

        .button {
            border: none;
            background-color: #fff;
            color: #1497fc;
        }

        .page {
            margin-top: 1.11rem;
        }
    }
</style>
